var reviewer_rs_manage = new Ext.data.JsonReader({
    root: 'manuscripts',
    totalProperty: 'totalCount'
}, [{
    name: 'manuscriptWorkId',// 稿件工作标识
    mapping: 'manuscriptWorks',
    hidden: 'true',
    convert: function(v, rec){
        return v[0].manuscriptWorkId;
    }
}, {
    name: 'urgence',// 紧急程度，取值见urgence常量
    mapping: 'urgence',
    hidden: 'true'
}, {
    name: 'manuscriptWorks',// 紧急程度，取值见urgence常量
    mapping: 'manuscriptWorks',
    hidden: 'true'
}, {
    name: 'securityClassification',// 密级，取值见securityClassification常量
    mapping: 'securityClassification',
    hidden: 'true'
}, {
    name: 'principalId',// 统稿人标识
    mapping: 'manuscriptWorks',
    hidden: 'true'
}, {
    name: 'status',// 统稿人是否领稿
    mapping: 'manuscriptWorks',
    hidden: 'true'
}, {
    name: 'manuscriptId',// 稿件标识
    mapping: 'manuscriptId',
    hidden: 'true'
}, {
    name: 'title',// 稿件标题
    mapping: 'title',
    convert: function(v, rec){
        if (v.length > 15) {
            return v.substring(0, 15) + "...";
        }
        else {
            return v;
        }
    }
}, {
    name: 'contributeCompanyName',// 单位
    mapping: 'contributeCompany.contributeCompanyName'
}, {
    name: 'manuscriptCategoryName',// 稿件分类
    mapping: 'manuscriptCategory.manuscriptCategoryName'
}, {
    name: 'plannedConsummationTime',// 计划完成时间
    mapping: 'manuscriptWorks',
    convert: function(v, rec){
        return v[0].plannedFinishedTime;
    }
}]);
var reviewer_ds_manamge = new Ext.data.Store({
    proxy: new Ext.data.HttpProxy({
        url: 'reviewer_listManuscriptWorksForPrincipal_list.action',
        method: 'POST'
    }),
    reader: reviewer_rs_manage
});
var reviewer_cm_user = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
    header: "稿件标题",
    width: 100,
    dataIndex: 'title',
    sortable: true,
    renderer: function(value, metadata, record){
        return "<a href = 'javascript:void(0)' onclick=javascript:reviewer_showmanageView('" +
        record.data.manuscriptId +
        "')> " +
        escapeHTML(value) +
        " </a>";
    }
}, {
    header: "来稿单位",
    width: 100,
    dataIndex: 'contributeCompanyName'

}, {
    header: "稿件分类",
    width: 120,
    dataIndex: 'manuscriptCategoryName'

}, {
    header: "要求完成时间",
    width: 120,
    dataIndex: 'plannedConsummationTime',
    sortable: true,
    renderer: function(value, metadata, record){
	 	return new Date(value).format('Y-m-d');
    }
}, {
    header: "标识",
    width: 80,
    dataIndex: 'manuscriptWorkId',
    renderer: function(value, metadata, record){
        return tomark(value, metadata, record);
        
    }
}, {
    header: "操作",
    width: 180,
    dataIndex: 'manuscriptWorkId',
    renderer: function(value, metadata, record){
        return touserCheck(value, metadata, record);
    }
}]);
// 操作START
function touserCheck(value, metadata, record){
    var tocheckmanage = "<span style='color:#CCCCCC'>分配&nbsp;</span>";
    var confirmmanage = "<span style='color:#CCCCCC'>确认&nbsp;</span>";
    var la = record.data.manuscriptWorks[0].manuscriptWorkers;
    for (var i = 0; i < la.length; i++) {
        if (la[i].manuscriptWorkerId != record.data.manuscriptWorks[0].principalId) {
            if (la[i].status == 0) {
                tocheckmanage = "<a href = 'javascript:void(0)' id = 'openUser' value='ss' name='open' onclick=javascript:reviewer_checkmanage('" +
                value +"','"+record.data.securityClassification+"','"+record.data.manuscriptId+
                "')>分配 </a>";
            }
            else 
                if ((la[i].status == 3 || la[i].status == 4) && la[i].confirmerId == null) {
                    confirmmanage = "<a href = 'javascript:void(0)' id = 'openUser' value='ss' name='open' onclick=javascript:reviewer_confirmmanage('" +
                    value +
                    "')>确认 </a>"
                }
        }
    };
    return tocheckmanage + confirmmanage + "<a href = 'javascript:void(0)' id = 'openUser' value='ss' name='open' onclick=javascript:reviewer_viewmanage('" +
    value +
    "')>查看 </a>";
}

// 操作END
// 单位START
// 单位END
// 时间操作START
function totime(value, metadata, record){
    return new Date(value).format('Y-m-d H:i');
}

// 时间操作END
// START

function tourgence(value){

    switch (value) {
        case 0:
            return "普通";
            break;
        case 5:
            return "紧急";
            break;
        case 10:
            return "特急";
            break;
    }
    
}

function tosecurityClassification(value){

    switch (value) {
        case 1:
            return "普通";
            break;
        case 2:
            return "秘密";
            break;
        case 3:
            return "机密";
            break;
        case 5:
            return "绝密";
            break;
    }
    
}

function tolanguage(value){

    switch (value) {
        case 1:
            return "汉语";
            break;
        case 2:
            return "藏语";
            break;
    }
    
}

function totargetLanguage(value){

    switch (value) {
        case 1:
            return "汉语";
            break;
        case 2:
            return "藏语";
            break;
    }
    
}

function totexttype(value){

    switch (value) {
        case 0:
            return "纸质稿件";
            break;
        case 0x0100:
            return "电子稿件";
            break;
    }
    
}

function totype(value) {
	if(value=="DW"){
		return "党委";
	}else if(value=="RD"){
		return "人大";
	}else if(value=="ZF"){
		return "政府";
	}else if(value=="ZX"){
		return "政协";
	}else if(value=="QT"){
		return "其他";
	}else{
		return value;
	}
}

function tolastModifierName(value){

    if (value == null) {
        return "";
    }
    else {
        return value;
    }
    
}

// END
// 表单START
var urgence;
var securityClassification;
var language;
var targetLanguage;
var contributeTime;
var plannedConsummationTime;
var type;
var texttype;
var lastModifierName;
var jhplannedConsummationTime;
function formchange(respText){

    lastModifierName = tolastModifierName(respText.manuscript.lastModifierName);
    urgence = tourgence(respText.manuscript.urgence);
    securityClassification = tosecurityClassification(respText.manuscript.securityClassification);
    language = tolanguage(respText.manuscript.language);
    targetLanguage = totargetLanguage(respText.manuscript.targetLanguage);
    contributeTime = totime(respText.manuscript.contributeTime, "", "");
    plannedConsummationTime = totime(respText.manuscriptWork.plannedFinishedTime, "", "");
    texttype = totexttype(respText.manuscript.type);
    type = totype(respText.contributeCompany.type);
	jhplannedConsummationTime=totime(respText.manuscript.plannedConsummationTime,"","");
}

// 表单END
// 标志START

var re;
function tomark(value, metadata, record) {
    var title = '&nbsp;密级&nbsp;&nbsp;&nbsp;&nbsp;紧急程度&nbsp;';
    var tip;
    var s1 = "&nbsp;普通&nbsp;&nbsp;&nbsp;&nbsp;";
    var s2 = "&nbsp;秘密&nbsp;&nbsp;&nbsp;&nbsp;";
    var s3 = "&nbsp;机密&nbsp;&nbsp;&nbsp;&nbsp;";
    var s5 = "&nbsp;绝密&nbsp;&nbsp;&nbsp;&nbsp;";
    var u0 = "&nbsp;&nbsp;&nbsp;普通&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
    var u5 = "&nbsp;&nbsp;&nbsp;紧急&nbsp;&nbsp;&nbsp;&nbsp;";
    var u10 = "&nbsp;&nbsp;&nbsp;特急";
    var c0 = "&nbsp<img src='images/clock_blue.gif'  />&nbsp";// 普通urgence
    var c5 = "&nbsp<img src='images/clock_green.gif' />&nbsp";// 紧急
    var c10 = "&nbsp<img src='images/clock_red.gif' />&nbsp";// 特急
    var l1 = "&nbsp<img src='images/lock_blue.gif'  />&nbsp";// 普通securityClassification
    var l2 = "&nbsp<img src='images/lock_gold.gif'/>&nbsp"; // 秘密
    var l3 = "&nbsp<img src='images/lock_green.gif' />&nbsp";// 机密
    var l5 = "&nbsp<img src='images/lock_red.gif'  />&nbsp";// 绝密
    switch (record.data.securityClassification) {
        case 1:
            switch (record.data.urgence) {
                case 0:
                	re = l1 + c0;
                    tip = s1 + u0;
                    break;
                case 5:
                	re = l1 + c5 ;
                    tip = s1 + u5;
                    break;
                case 10:
                	re = l1 + c10;
                    tip = s1 + u10;
                    break;
            }
            break;
        case 2:
            switch (record.data.urgence) {
                case 0:
                	re = l2 + c0;
                    tip = s2 + u0;
                    break;
                case 5:
                	re = l2 + c5;
                    tip = s2 + u5;
                    break;
                case 10:
                	re = l2 + c10;
                    tip = s2 + u10;
                    break;
            }
            break;
        case 3:
            switch (record.data.urgence) {
	            case 0:
	            	re = l3 + c0;
	                tip = s3 + u0;
	                break;
	            case 5:
	            	re = l3 + c5;
	                tip = s3 + u5;
	                break;
	            case 10:
	            	re = l3 + c10;
	                tip = s3 + u10;
	                break;
            }
            
            break;
        case 5:
            switch (record.data.urgence) {
	            case 0:
	            	re = l5 + c0;
	                tip = s5 + u0;
	                break;
	            case 5:
	            	re = l5 + c5;
	                tip = s5 + u5;
	                break;
	            case 10:
	            	re = l5 + c10;
	                tip = s5 + u10;
	                break;
	            }
            break;
    }
    metadata.attr = 'ext:qtitle="' + title + '"' + ' ext:qtip="' + tip + '"';
    return re;
}

// 标志END
// 查看稿件
window.reviewer_showmanageView = function(needParam){
    Ext.Ajax.request({
        url: 'reviewer_listoneManuscript_view.action',
        method: 'post',
        params: {
            manuscriptId: needParam
        },
        success: function(resp, opts){
            var respText = Ext.util.JSON.decode(resp.responseText);
            if (respText.success) {
                formchange(respText);
                var reviewer_reviewer_window_manageView = new Ext.Window({
                    closable: false,
                    title: '稿件详情',
                    iconCls: 'manuscript',
                    width: 600,
                    resizable: false,
                    autoHeight: true,
                    modal: true,
                    constrain: true,
                    closeAction: 'hide',
                    items: [new Ext.FormPanel({
                        border: false,
                        labelAlign: 'right',
                        labelWidth: 100,
                        frame: true,
                        items: [{
                            fieldLabel: '稿件标题',
                            xtype: 'textfield',
                            readOnly: true,
                            width: 425,
                            itemCls: "unedit",
                            value: respText.manuscript.title
                        },{
							autoHeight : true,
							xtype : 'textfield',
							fieldLabel : '稿件编号',
							readOnly : true,
							value : respText.manuscript.manuscriptCode,
							itemCls:'form_text unedit'
						}, {
                            autoHeight: true,
                            xtype: 'textfield',
                            fieldLabel: '来稿单位',
                            readOnly: true,
                            itemCls: 'form_text unedit',
                            value: respText.contributeCompany.contributeCompanyName
                        
                        }, {
                            autoHeight: true,
                            xtype: 'textfield',
                            fieldLabel: '来稿单位类型',
                            readOnly: true,
                            itemCls: 'form_text unedit',
                            value: type
                        
                        }, {
                            autoHeight: true,
                            xtype: 'textfield',
                            fieldLabel: '联系人',
                            readOnly: true,
                            itemCls: 'form_text unedit',
                            value: respText.contributeCompanyPerson.name
                        
                        }, {
                            autoHeight: true,
                            xtype: 'textfield',
                            fieldLabel: '联系人手机',
                            readOnly: true,
                            itemCls: 'form_text unedit',
                            value: respText.contributeCompanyPerson.mobilePhone
                        
                        }, {
                            autoHeight: true,
                            xtype: 'textfield',
                            fieldLabel: '联系人邮箱',
                            readOnly: true,
                            itemCls: 'form_text unedit',
                            value: respText.contributeCompanyPerson.email
                        
                        }, {
                            autoHeight: true,
                            xtype: 'textfield',
                            fieldLabel: '稿件分类',
                            readOnly: true,
                            itemCls: 'form_text unedit',
                            value: respText.manuscriptCategory.manuscriptCategoryName
                        
                        }, {
                            autoHeight: true,
                            xtype: 'textfield',
                            fieldLabel: '紧急程度',
                            readOnly: true,
                            itemCls: 'form_text unedit',
                            value: urgence
                        
                        }, {
                            autoHeight: true,
                            xtype: 'textfield',
                            fieldLabel: '文档类型',
                            readOnly: true,
                            itemCls: 'form_text unedit',
                            value: texttype
                        
                        }, {
                            autoHeight: true,
                            xtype: 'textfield',
                            fieldLabel: '原稿文种',
                            readOnly: true,
                            itemCls: 'form_text unedit',
                            value: language
                        
                        }, {
                            autoHeight: true,
                            xtype: 'textfield',
                            fieldLabel: '密级',
                            readOnly: true,
                            itemCls: 'form_text unedit',
                            value: securityClassification
                        
                        }, {
                            autoHeight: true,
                            xtype: 'textfield',
                            fieldLabel: '目标语言',
                            readOnly: true,
                            itemCls: 'form_text unedit',
                            value: targetLanguage
                        
                        }, {
                            autoHeight: true,
                            xtype: 'textfield',
                            fieldLabel: '字数',
                            readOnly: true,
                            itemCls: 'form_text unedit',
                            value: respText.manuscript.wordNum
                        
                        }, {
                            autoHeight: true,
                            xtype: 'textfield',
                            fieldLabel: '来稿时间',
                            readOnly: true,
                            itemCls: 'form_text unedit',
                            value: contributeTime
                        
                        }, {
                            autoHeight: true,
                            xtype: 'textfield',
                            fieldLabel: '计划完成时间',
                            readOnly: true,
                            itemCls: 'form_text unedit',
                            value: jhplannedConsummationTime
                        
                        }, {
                            autoHeight: true,
                            xtype: 'textfield',
                            fieldLabel: '创建人',
                            readOnly: true,
                            itemCls: 'form_text unedit',
                            value: respText.manuscript.creatorName
                        
                        }, {
                            autoHeight: true,
                            xtype: 'textfield',
                            fieldLabel: '最后修改人',
                            readOnly: true,
                            itemCls: 'form_text unedit',
                            value: lastModifierName
                        
                        }, {
                            fieldLabel: '备注',
                            xtype: 'panel',
                            width: 425,
                            itemCls: 'clear',
                            html: changeRemark(respText)
                        }],
                        buttons: [{
                            text: '关闭',
                            handler: function(){
                                reviewer_reviewer_window_manageView.hide();
                            }
                        }]
                    })]
                
                }).show();
            }
            else {
                Ext.Msg.alert('查看详情失败');
            }
        },
        failure: function(){
            Ext.Msg.show({
                title: '错误提示',
                msg: '查看失败!',
                buttons: Ext.Msg.OK,
                icon: Ext.Msg.ERROR,
                width: 200
            });
        }
    });
}
function changeRemark(respText){
    return "<div align=\"center\"><a href='javascript:void(0)'  onclick=javascript:showRemark('" + respText.manuscript.manuscriptId + "')>备注详情</a></div>";
}

window.showRemark = function(v){
    Ext.Ajax.request({
        url: 'reviewer_listoneManuscript_view.action',
        method: 'post',
        params: {
            manuscriptId: v
        },
        success: function(resp, opts){
            var respText = Ext.util.JSON.decode(resp.responseText);
            if (respText.success) {
                var window_remark = new Ext.Window({
                    title: '备注详情',
                    closable: false,
                    width: 600,
                    resizable: false,
                    height: 400,
                    iconCls: 'manuscript',
                    modal: true,
                    constrain: true,
                    closeAction: 'close',
                    layout: 'fit',
                    items: [{
                        xtype: 'htmleditor',
                        enableAlignments: false,
                        enableColors: false,
                        enableFont: false,
                        enableFontSize: false,
                        enableFormat: false,
                        enableLinks: false,
                        enableLists: false,
                        enableSourceEdit: false,
                        readOnly: true,
                        value: respText.manuscript.remark
                    }],
                    buttons: [{
                        text: '关闭',
                        handler: function(){
                            window_remark.close();
                        }
                    }]
                
                
                }).show();
            }
        },
        failure: function(){
            Ext.Msg.show({
                title: '错误提示',
                msg: '查看失败!',
                buttons: Ext.Msg.OK,
                icon: Ext.Msg.ERROR,
                width: 200
            });
        }
    })
}
/*
 * 查 /* 查看稿件END
 */
/*
 * 循环添加部分
 */
var manuscriptWorkersId = "";
function getFormInput_manage(f, respText){
	totalWordNum=respText.manuscriptWork.wordNum;//总字数
    var twordNum = new Ext.form.TextField({
        autoHeight: true,
        fieldLabel: '字数',
        readOnly: true,
        width: 425,
        itemCls: 'unedit',
        value: respText.manuscriptWork.wordNum
    });
    var tmanuscriptWorkerName = {
        autoHeight: true,
        xtype: 'textfield',
        fieldLabel: '统稿人',
        readOnly: true,
        itemCls: 'form_text unedit',
        value: respText.manuscriptWorker.manuscriptWorkerName
    
    };
    var tinput = {
            autoHeight: true,
            xtype: 'numberfield',
            id: 'wnum',
            itemCls: 'form_text',
            allowBlank: false,
            blankText: '不能为空!',
            fieldLabel: '字数',
            validator:function(value){
        		var regex= /^[1-9][0-9]{0,8}$/;
        		if(!regex.test(value)){
        			return "只能输入不超过9位的正整数!";
        		}else{
        			if(value>=totalWordNum){
        				return "输入的字数要求小于稿件总字数";
        			}else{
        				return addLastWordNum(f,respText,value,totalWordNum);;
        			}
        		}
        	}
        };
    f.add(twordNum);
    if ((respText.manuscriptWorker.status == 0) || (respText.manuscriptWorker.status == 1) || (respText.manuscriptWorker.status == 2)) {
        f.add(tmanuscriptWorkerName);
        f.add(tinput);
    }
    for (var i = 0; i < respText.manuscriptWorkers.length; i++) {
        if (respText.manuscriptWorkers[i].status == 0) {
            var mm = new Ext.form.TextField({
                autoHeight: true,
                fieldLabel: '工作人员',
                readOnly: true,
                itemCls: 'form_text unedit',
                value: respText.manuscriptWorkers[i].manuscriptWorkerName
            
            });
            var ss = "mnum" + i;
            var aa = new Ext.form.NumberField({
                autoHeight: true,
                id: ss,
                itemCls: 'form_text',
                allowBlank: false,
                blankText: '不能为空!',
                fieldLabel: '字数',
                validator:function(value){
	        		var regex= /^[1-9][0-9]{0,8}$/;
	        		if(!regex.test(value)){
	        			return "只能输入不超过9位的正整数!";
	        		}else{
	        			if(value>=totalWordNum){
	        				return "输入的字数要求小于稿件总字数";
	        			}else{
	        				return addLastWordNum(f,respText,value,totalWordNum);
	        			}
	        		}
	        	}
            });
            f.add(mm);
            f.add(aa);
        };
            }
    var fileUpload=new Ext.form.FileUploadField({
    	fieldLabel : '稿件上传',
    	name : 'upload',
		id: 'upload',
		emptyText : '请选择文件(最大允许值50M)',
		allowBlank : false,
		width : '410',
		validator : function(value) {
			var type = ['rar', 'doc', 'xls', 'pdf', 'ppt',
					'txt', 'zip', 'docx'];
			if (value == '') {
				return '请上传稿件';
			} else {
				var fileType = value.substring(value
						.lastIndexOf(".")
						+ 1).toLowerCase();
				for (var i = 0; i < type.length; i++) {
					if (type[i] == fileType) {
						return true;
					}
				}
				return '请上传如下格式的文件:[rar,doc,xls,pdf,ppt,txt,zip,docx]';
			}
		},
		itemCls : 'clear'
    });
    f.add(fileUpload);
}

var jsonNum=[]; 
var objValue;
var sumValue=0;//所填的任务字数的和

/**自动填写最后一个任务字数功能**/
function addLastWordNum(f,respText,value,totalWordNum){
	var adminWordNum=Ext.getCmp("wnum").getValue();//统稿人的字数
	if(adminWordNum==""){
		adminWordNum=0;
	}
	jsonNum[0]=adminWordNum;
	sumValue=adminWordNum;
	for (var j = 0; j < respText.manuscriptWorkers.length; j++) {
		var wokerNum=Ext.getCmp("mnum"+j).getValue();
		if(wokerNum==""){
			wokerNum=0;
		}
		jsonNum[j+1]=wokerNum;
		sumValue+=wokerNum;
	}
	if(sumValue>totalWordNum){//如果所填的字数大于总字数
		return "字数总和不能超过总字数";
	}else{/**==================实现自动填写最后一个输入的工作人员的字数================**/
		f.getForm().clearInvalid();//数据合理后清除错误样式
		var isHasNull= jsonNum.indexOf(0);
		var lastNull=jsonNum.lastIndexOf(0);
		if(isHasNull!=-1&&isHasNull==lastNull){//字数数组中有且只有一个null时
			if(lastNull==0){
				Ext.getCmp("wnum").setValue(totalWordNum-sumValue);
			}else{
				Ext.getCmp("mnum"+(lastNull-1)).setValue(totalWordNum-sumValue);
			}
		}else if(isHasNull==-1){
			if(sumValue!=totalWordNum){
				return "工作人员的总字数与稿件总字数不相等";
			}
		}
		return true;
	}
	
}

/*
 * 循环添加部分
 */
function chageString(respText){
    var cstring = "";
    for (var i = 0; i < respText.manuscriptWorkers.length; i++) {
        var ss = "mnum" + i;
        if (respText.manuscriptWorkers[i].status == 0) {
        
            cstring += respText.manuscriptWorkers[i].manuscriptWorkerId + "-" +
            Ext.getCmp(ss).getValue() +
            ",";
        }
    }
    return cstring;
}

function prWordNum(respText){
    var prWordNum = 0;
    if ((respText.manuscriptWorker.status == 0) || (respText.manuscriptWorker.status == 1) || (respText.manuscriptWorker.status == 2)) {
        prWordNum = Ext.getCmp('wnum').getValue();
    }
    return prWordNum;
}

// 是否已分配
var isCheck = false;
function toisCheck(value){
    var fag = 0;
    for (var i = 0; i < value.manuscriptWorkers.length; i++) {
        if (value.manuscriptWorkers[i].status >= 1) {
            fag++;
        }
    }
    if (fag == value.manuscriptWorkers.length) {
        isCheck = false;
    }
    else {
        isCheck = true;
    }
    
}

// 查看操作START
window.reviewer_checkmanage = function(needParam,securityClassification,manuscriptId){
    Ext.Ajax.request({
        url: 'reviewer_listWorkersByManuscriptWorkId_list.action',
        method: 'post',
        params: {
            manuscriptWorkId: needParam
        },
        success: function(resp, opts){
            var respText = Ext.util.JSON.decode(resp.responseText);
            if (respText.success) {
                toisCheck(respText);
                var reviewer_form_manage = new Ext.FormPanel({
                    border: false,
                    labelAlign: 'right',
                    labelWidth: 100,
                    frame: true,
                    fileUpload: true,
                    enctype: 'multipart/form-data',
                    items: [],
                    buttons: [{
                        text: '分配',
                        handler: function(){
                            if (reviewer_form_manage.form.isValid()) {
                            	reviewer_form_manage.getForm().submit({
                                    url: 'reviewer_assignWorkToManuscriptWorkers_assign.action',
                                    method: 'post',
                                    waitMsg : '请稍等......',
                                    params: {
                            			manuscriptId:manuscriptId,
                                        manuscriptWorkId: respText.manuscriptWorker.manuscriptWorkId,
                                        wordNum: prWordNum(respText),
                                        manuscriptWorkersId: chageString(respText),
                                        securityClassification:securityClassification
                                    },
                                    success: function(c,resp, opts){
                                    	var respText = Ext.util.JSON.decode(resp.response.responseText);
                                        if (respText.success) {
                                        	if(respText.uploadSuccess==undefined){
                                        		Ext.Msg.show({
                									title: '操作提示',
                									msg: '文件大于最大允许值50M!',
                									buttons: Ext.Msg.OK,
                									icon: Ext.Msg.ERROR,
                									width: 200
                								});
                                        	}else if(respText.uploadSuccess=="true"){
                                        		reviewer_window_manage.close();
                                        		reviewer_window_manage.remove(Ext.getCmp('wnum'));
                                        		Ext.Msg.show({
                                        			title: '成功提示',
                                        			msg: respText.msg,
                                        			buttons: Ext.Msg.OK,
                                        			icon: Ext.Msg.INFO,
                                        			width: 200,
                                        			fn:function(){
	                                        			reviewer_ds_manamge.load({
	                                        				params: {
	                                        				start: 0,
	                                        				limit: 20
	                                        			}
	                                        			});
                                        			}
                                        		});
                                        	}
                                            
                                        }
                                        else {
                                            Ext.Msg.show({
                                                title: '错误提示',
                                                msg: respText.msg,
                                                buttons: Ext.Msg.OK,
                                                icon: Ext.Msg.ERROR,
                                                width: 200
                                            });
                                        }
                                    },
                                    failure: function(){
                                        Ext.Msg.show({
                                            title: '错误提示',
                                            msg: '分配失败!',
                                            buttons: Ext.Msg.OK,
                                            icon: Ext.Msg.ERROR,
                                            width: 200
                                        });
                                    }
                                    
                                });
                            }
                            else {
                                Ext.Msg.show({
                                    title: '错误提示',
                                    msg: '数据不合法!',
                                    buttons: Ext.Msg.OK,
                                    icon: Ext.Msg.ERROR,
                                    width: 200
                                });
                            }
                        }
                    }, {
                        text: '返回',
                        handler: function(){
                            reviewer_window_manage.close();
                            reviewer_window_manage.remove(Ext.getCmp('wnum'));
                        }
                    }]
                
                });
                getFormInput_manage(reviewer_form_manage, respText);// 获得formPanel的子集里面的第一个对象,也就是fieldSet
                reviewer_form_manage.doLayout();
                if (isCheck) {
                    var reviewer_window_manage = new Ext.Window({
                        closable: false,
                        title: '查看',
                        constrain: true,
                        iconCls: 'work_finish',
                        width: 600,
                        resizable: false,
                        autoHeight: true,
                        modal: true,
                        closeAction: 'hide',
                        items: [reviewer_form_manage]
                    
                    }).show();
                }
                else {
                    Ext.Msg.show({
                        title: '错误提示',
                        msg: '任务已分配!',
                        buttons: Ext.Msg.OK,
                        icon: Ext.Msg.ERROR,
                        width: 200
                    });
                }
                
            }
            else {
                Ext.Msg.show({
                    title: '错误提示',
                    msg: respText.msg,
                    buttons: Ext.Msg.OK,
                    icon: Ext.Msg.ERROR,
                    width: 200
                });
            }
        },
        failure: function(){
            Ext.Msg.show({
                title: '错误提示',
                msg: '查看失败!',
                buttons: Ext.Msg.OK,
                icon: Ext.Msg.ERROR,
                width: 200
            });
        }
    });
}

/*
 * 交稿操作END
 */
// 确认操作START
/*
 * 循环添加部分
 */
var status;
function tostatu(value){
    switch (value) {
        case 0:
            return "分发完成 ";
            break;
        case 1:
            return "工作已分配";
            break;
        case 2:
            return "工作被接受";
            break;
        case 3:
            return "工作被拒绝";
            break;
        case 4:
            return "工作提交完成";
            break;
        case 5:
            return "工作被确认完成";
            break;
    }
    
}

var manuscriptWorkerIds = "";
var manuscriptWorkId = 1;
var isNull = false;
function getFormconfirm(f, respText){

    for (var i = 0; i < respText.manuscriptWorkers.length; i++) {
        if (respText.manuscriptWorkers[i].status < 5) {
            var mm = new Ext.form.TextField({
                autoHeight: true,
                fieldLabel: '工作人员',
                readOnly: true,
                itemCls: 'form_text unedit',
                value: respText.manuscriptWorkers[i].manuscriptWorkerName
            
            });
            var aa = new Ext.form.TextField({
                autoHeight: true,
                fieldLabel: '工作状态',
                readOnly: true,
                itemCls: 'form_text unedit',
                value: tostatu(respText.manuscriptWorkers[i].status)
            
            });
            manuscriptWorkId = respText.manuscriptWorkId;
            manuscriptWorkerIds += respText.manuscriptWorkers[i].manuscriptWorkerId +
            ",";
        }
        f.add(mm);
        f.add(aa);
    };
    }

function toisNull(value){
    if (value.manuscriptWorkers.length == 0) {
        isNull = false;
    }
    else {
        isNull = true;
    }
}

/*
 * 循环添加部分
 */
window.reviewer_confirmmanage = function(needParam){
    Ext.Ajax.request({
        url: 'reviewer_listManuscriptWorksWaitingForConfirming_list.action',
        method: 'post',
        params: {
            manuscriptWorkId: needParam,
            pageSize: 20
        },
        success: function(resp, opts){
            var respText = Ext.util.JSON.decode(resp.responseText);
            if (respText.success) {
                toisNull(respText);
                var reviewer_form_con = new Ext.FormPanel({
                
                    border: false,
                    labelAlign: 'right',
                    labelWidth: 100,
                    frame: true,
                    fileUpload: true,
                    items: [],
                    buttons: [{
                        text: '确认',
                        handler: function(){
                            Ext.Ajax.request({
                                url: 'reviewer_confirmManuscriptWorkers_confirm.action',
                                method: 'post',
                                params: {
                                    manuscriptWorkId: manuscriptWorkId,
                                    manuscriptWorkerIds: manuscriptWorkerIds
                                },
                                success: function(resp, opts){
                                    var respText = Ext.util.JSON.decode(resp.responseText);
                                    if (respText.success) {
                                        reviewer_window_con.close();
                                        Ext.Msg.show({
                                            title: '成功提示',
                                            msg: '确认成功!',
                                            buttons: Ext.Msg.OK,
                                            icon: Ext.Msg.INFO,
                                            width: 200
                                        });
                                        reviewer_ds_manamge.load({
                                            params: {
                                                start: 0,
                                                limit: 20
                                            }
                                        });
                                    }
                                    else {
                                        reviewer_window_con.close();
                                        reviewer_window_con.remove(Ext.getCmp('wnum'));
                                        Ext.Msg.show({
                                            title: '错误提示',
                                            msg: respText.msg,
                                            buttons: Ext.Msg.OK,
                                            icon: Ext.Msg.ERROR,
                                            width: 300
                                        });
                                    }
                                },
                                failure: function(){
                                    Ext.Msg.show({
                                        title: '错误提示',
                                        msg: '确认失败!',
                                        buttons: Ext.Msg.OK,
                                        icon: Ext.Msg.ERROR,
                                        width: 200
                                    });
                                }
                                
                            })
                        }
                    }, {
                        text: '返回',
                        handler: function(){
                            reviewer_window_con.close();
                            reviewer_window_con.remove(Ext.getCmp('wnum'));
                        }
                    }]
                });
                getFormconfirm(reviewer_form_con, respText);// 获得formPanel的子集里面的第一个对象,也就是fieldSet
                reviewer_form_con.doLayout();
                if (isNull) {
                    var reviewer_window_con = new Ext.Window({
                        closable: false,
                        iconCls: 'manuscript',
                        width: 600,
                        title: '确认工作',
                        resizable: false,
                        autoHeight: true,
                        modal: true,
                        constrain: true,
                        closeAction: 'hide',
                        items: [reviewer_form_con]
                    
                    
                    }).show();
                }
                else {
                    Ext.Msg.show({
                        title: '错误提示',
                        msg: '暂无需确认的工作!',
                        buttons: Ext.Msg.OK,
                        icon: Ext.Msg.ERROR,
                        width: 300
                    });
                }
                
            }
            else {
                Ext.Msg.show({
                    title: '错误提示',
                    msg: respText.msg,
                    buttons: Ext.Msg.OK,
                    icon: Ext.Msg.ERROR,
                    width: 300
                });
            }
        },
        failure: function(){
            Ext.Msg.show({
                title: '错误提示',
                msg: '查看失败!',
                buttons: Ext.Msg.OK,
                icon: Ext.Msg.ERROR,
                width: 200
            });
        }
    });
}

/*
 * 确认操作END
 */
/*
 查看工作START
 */
function tomanscripCheck(value, metadata, record){
    if (record.data.status >= 4) {
    	var refEntityId = (record.data.manuscriptWorkId).toString() + (record.data.manuscriptWorkerId).toString();
        return "<a href = 'javascript:void(0)' id = 'openUser' value='ss' name='open' onclick=javascript:reviewer_myUpload('" +
        refEntityId + "','ManuscriptWorker')>下载附件 </a>";
    }
    else {
        return "无附件";
    }
}

/*
 * 下载稿START
 */
window.reviewer_myUpload = function(refEntityId,refEntityType){
    Ext.Ajax.request({
        url: 'reviewer_downloadManuscript_download.action',
        method: 'post',
        params: {
	    	refEntityId: refEntityId,
			refEntityType:refEntityType
        },
        success: function(resp, opts){
            var respText = Ext.util.JSON.decode(resp.responseText);
            if (respText.success) {
                if (respText.entityPaths != null) {
                    download(respText.entityPaths, refEntityId, refEntityType);
                }
                else {
                    Ext.Msg.show({
                        title: '错误提示',
                        msg: respText.msg,
                        buttons: Ext.Msg.OK,
                        icon: Ext.Msg.ERROR,
                        width: 200
                    });
                }
            }
            else {
                Ext.Msg.show({
                    title: '错误提示',
                    msg: respText.msg,
                    buttons: Ext.Msg.OK,
                    icon: Ext.Msg.ERROR,
                    width: 200
                });
            }
        },
        failure: function(){
            Ext.Msg.show({
                title: '错误提示',
                msg: '没有附件!',
                buttons: Ext.Msg.OK,
                icon: Ext.Msg.ERROR,
                width: 200
            });
        }
    });
}
function download(entityPaths, refEntityId, refEntityType){
    var path = "download.action?inputPath=" + entityPaths + "&refEntityId=" + refEntityId + "&refEntityType=" + refEntityType;
    window.location.href = path;
}

/*
 * 下载稿END\
 */
function reviewer_wordNumView(needParam, metadata, record){
    if (record.data.remark != '') {
        return "<a href = 'javascript:void(0)' id = 'll' value='rtr' name='et' onclick=javascript:reviewer_myWordNum('" +
        needParam +
        "','" +
        record.data.manuscriptWorkerId +
        "')>任务备注 </a>";
    }
    else {
        return '无备注';
    }
}

window.reviewer_myWordNum = function(needParam, value){
    Ext.Ajax.request({
        url: 'reviewer_listWorkersByManuscriptWorkId_list.action',
        method: 'post',
        params: {
            manuscriptWorkId: needParam
        },
        success: function(resp, opts){
            var respText = Ext.util.JSON.decode(resp.responseText);
            var remark = '';
            if (respText.success) {
                for (var i = 0; i < respText.manuscriptWorkers.length; i++) {
                    if (respText.manuscriptWorkers[i].manuscriptWorkerId == value) {
                        remark = respText.manuscriptWorkers[i].remark;
                    }
                };
                Ext.Msg.show({
                    title: '任务备注',
                    msg: remark,
                    width: 300,
                    buttons: Ext.Msg.OK,
                    icon: Ext.Msg.INFO
                });
            }
        },
        failure: function(){
            Ext.Msg.show({
                title: '错误提示',
                msg: '查看失败!',
                buttons: Ext.Msg.OK,
                icon: Ext.Msg.ERROR,
                width: 200
            });
        }
    });
}
window.reviewer_viewmanage = function(needParam){
    var reviewer_rs_view = new Ext.data.JsonReader({
        root: 'manuscriptWorkers',
        totalProperty: 'totalCount'
    }, [{
        name: 'manuscriptWorkId',// 稿件工作标识
        mapping: 'manuscriptWorkId',
        hidden: 'true'
    }, {
        name: 'manuscriptWorkerId',// 稿件工作人员标识
        mapping: 'manuscriptWorkerId',
        hidden: 'true'
    }, {
        name: 'manuscriptWorkerName', // 稿件工作人员姓名
        mapping: 'manuscriptWorkerName'
    }, {
        name: 'plannedFinishedTime',// 计划完成时间
        mapping: 'plannedFinishedTime'
    }, {
        name: 'startTime',// 工作开始时间
        mapping: 'startTime'
    }, {
        name: 'actualFinishedTime',//实际完成时间
        mapping: 'actualFinishedTime'
    }, {
        name: 'status',
        mapping: 'status'
    }, {
        name: 'wordNum',
        mapping: 'wordNum'
    }, {
        name: 'remark',
        mapping: 'remark'
    }]);
    var reviewer_ds_view = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: 'reviewer_listWorkersByManuscriptWorkId_list.action?manuscriptWorkId=' + needParam,
            method: 'POST'
        }),
        reader: reviewer_rs_view
    });
    var reviewer_cm_view = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
        header: "工作人员",
        width: 80,
        dataIndex: 'manuscriptWorkerName'
    
    }, {
        header: "要求完成时间",
        width: 100,
        dataIndex: 'plannedFinishedTime',
        renderer: function(value, metadata, record){
            return totime(value, metadata, record);
        }
        
    }, {
        header: "工作开始时间",
        width: 100,
        dataIndex: 'startTime',
        renderer: function(value, metadata, record){
            return totime(value, metadata, record);
        }
        
    }, {
        header: "实际完成时间",
        width: 100,
        dataIndex: 'actualFinishedTime',
        renderer: function(value, metadata, record){
            if (value == '') {
            
                return "未完成";
            }
            else {
                return totime(value, metadata, record);
            }
        }
        
    }, {
        header: "字数",
        width: 80,
        dataIndex: 'wordNum'
    
    }, {
        header: "工作状态",
        width: 120,
        dataIndex: 'status',
        renderer: function(value, metadata, record){
            return tostatu(value);
        }
    }, {
        header: "任务备注",
        width: 80,
        dataIndex: 'remark',
        renderer: function(value, metadata, record){
            return reviewer_wordNumView(needParam, metadata, record);
        }
    }, {
        header: "操作",
        width: 100,
        dataIndex: 'manuscriptWorkerId',
        renderer: function(value, metadata, record){
            return tomanscripCheck(value, metadata, record);
        }
    }]);
    var reviewer_grid_view = new Ext.grid.GridPanel({
        loadMask: {
            msg: '数据加载中...'
        },
        ds: reviewer_ds_view,
        store: reviewer_ds_view,
        region: 'center',
        autoScroll: true,
        cm: reviewer_cm_view,
        autoExpandColumn: 5,
        autoWidth: true,
        height: 300,
        bbar: new Ext.PagingToolbar({
            pageSize: 20,
            store: reviewer_ds_view,
            displayInfo: true,
            beforePageText: '第',
            afterPageText: '页-共{0}页',
            displayMsg: '显示{0} - {1} 条  共 {2} 条',
            emptyMsg: "没有记录"
        })
    });
    reviewer_ds_view.load({
        params: {
            start: 0,
            limit: 20
        }
    });
    var reviewer_window_view = new Ext.Window({
        closable: false,
        title: '审核待管理的工作',
        width: 800,
        iconCls: 'manuscript',
        resizable: false,
        Height: true,
        modal: true,
        constrain: true,
        closeAction: 'hide',
        items: [reviewer_grid_view],
        buttons: [{
            text: '返回',
            handler: function(){
                reviewer_window_view.close();
                reviewer_window_view.remove(Ext.getCmp('wnum'));
            }
        }]
    
    }).show();
}
/*
 查看工作END
 */
var reviewer_grid_manage = new Ext.grid.GridPanel({
    title: '审核待管理的工作',
    loadMask: {
        msg: '数据加载中...'
    },
    ds: reviewer_ds_manamge,
    store: reviewer_ds_manamge,
    region: 'center',
    autoScroll: true,
    cm: reviewer_cm_user,
    autoExpandColumn: 1,
    bbar: new Ext.PagingToolbar({
        pageSize: 20,
        store: reviewer_ds_manamge,
        displayInfo: true,
        beforePageText: '第',
        afterPageText: '页-共{0}页',
        displayMsg: '显示{0} - {1} 条  共 {2} 条',
        emptyMsg: "没有记录"
    })
});
reviewer_ds_manamge.load({
    params: {
        start: 0,
        limit: 20
    }
});
var reviewer_p_manage = {
    id: 'reviewer-manage',
    border: false,
    layout: 'border',
    items: [reviewer_grid_manage]
};
Ext.getCmp('content-panel').add(reviewer_p_manage);
Ext.getCmp('content-panel').layout.setActiveItem('reviewer-manage');
